/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.pseudoelement;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.extensionpoints.palette.RegisteredMenu;
import com.cea.papyrus.diagraminterchange2.di2.GraphEdge;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * Utility class.
 */
public class EnhancedType {

	/**
	 * Get the new object description from CreateConnectionRequest
	 * The result is either a java.lang.Class
	 * or an Object...
	 * 
	 * @param request 
	 * 
	 * @return 
	 */
	public static Object getNewObjectDescription(CreateRequest request) {
		Object newObjectDescription;
		
		if (request.getNewObject() != null) {
			newObjectDescription = request.getNewObject();
			
		} else if (request.getNewObjectType() != null) {
			newObjectDescription = request.getNewObjectType();
			
		} else {
			newObjectDescription = null;
		}
		
		return newObjectDescription;
	}
	
	/**
	 * Return the list of enhanced type created by extensions buttons that match
	 * current GraphEdge.
	 * 
	 * @param gEdge 
	 * 
	 * @return 
	 */
	public static List<EnhancedType> getExistingObjectDescriptions(GraphEdge gEdge) {
			
		Uml1SemanticModelBridge umlBridge = (Uml1SemanticModelBridge) gEdge.getSemanticModel();
		if ((umlBridge == null) || (umlBridge.getElement() == null)) {
			return new ArrayList<EnhancedType>();
		}		
		Element connection = umlBridge.getElement();
		
		return RegisteredMenu.getMatchingTypes(connection);
	}
	
	/**
	 * 
	 * 
	 * @param gNode 
	 * 
	 * @return 
	 */
	public static List<EnhancedType> getExistingObjectDescriptions(GraphNode gNode) {
		return new ArrayList<EnhancedType>();
	}
}